import java.util.ArrayList;
import java.util.Arrays;

public class MyStack {
    int[] elem;
    int usedSize;

    public MyStack() {
        this.elem = new int[10];
    }

    public void push(int val){
        if(isFull()){
            this.elem = Arrays.copyOf(elem,2 * elem.length);
        }
        elem[usedSize++] = val;
    }

    private boolean isFull(){
        return usedSize == elem.length;
    }

    public int pop(){
        if(isEmpty()){
            throw new EmptyStackException("栈为空");
        }

        int val2 = elem[usedSize - 1];
        usedSize--;
        return val2;
    }

    public int peek(){
        if(isEmpty()){
            throw new EmptyStackException("栈为空");
        }
        return elem[usedSize - 1];
    }

    private boolean isEmpty(){
        return usedSize == 0;
    }

}
